package com.flyou.ccnucenter.ui.frgment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyou.ccnucenter.Constant;
import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.ui.frgment.HenuImage.Autumn;
import com.flyou.ccnucenter.ui.frgment.HenuImage.ShouHui;
import com.flyou.ccnucenter.ui.frgment.HenuImage.Spring;
import com.flyou.ccnucenter.ui.frgment.HenuImage.Summer;
import com.flyou.ccnucenter.ui.frgment.HenuImage.Winter;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.simple.eventbus.EventBus;


public class HenuImageFragment extends BaseFragment {
    private View mParentView;
    private SmartTabLayout mTabLayout;
    private ViewPager mViewPager;

    @Override
    protected View onCreatView(LayoutInflater inflater, ViewGroup container) {

        mParentView = inflater.inflate(R.layout.fragment_henu_image, container, false);
        return mParentView;

    }

    @Override
    protected void initData() {
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getChildFragmentManager(), FragmentPagerItems.with(context)
                .add(getString(R.string.image_minhlun), ShouHui.class)
                .add(getString(R.string.image_spring), Spring.class)
                .add(getString(R.string.image_summer), Summer.class)
                .add(getString(R.string.image_autumn), Autumn.class)
                .add(getString(R.string.image_winter), Winter.class)


                .create());
        mViewPager.setOffscreenPageLimit(0);
        if(mViewPager.getAdapter() == null) {
            mViewPager.setAdapter(adapter);
        }

        mTabLayout.setViewPager(mViewPager);
        mTabLayout.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                if (position>0) {
                    EventBus.getDefault().post("", Constant.DISABLE_MENU);
                }
                else {
                    EventBus.getDefault().post("", Constant.ENABLE_MENU);
                }
                super.onPageSelected(position);
            }
        });
    }

    @Override
    protected void initView() {
        mTabLayout= (SmartTabLayout) mParentView.findViewById(R.id.viewpagertab);
        mViewPager= (ViewPager) mParentView.findViewById(R.id.viewpager);
    }
    @Override
    public void onDestroy() {
        Log.d("HenuImageFragment", "onDestroy");
        EventBus.getDefault().post("", Constant.ENABLE_MENU);
        super.onDestroy();


    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        Log.d("HenuImageFragment", "onCreate");
    }
}
